import { makeAutoObservable } from 'mobx'
import type { IFormStatisticArrItem, TrainingStatisticRes } from './interface'
import { getTrainingsStatisticInfo } from './api'

class Store {
    /** 用户登录信息 */
    userInfo: any = {}

    /** 拍卖表统计 */
    form_statistic_arr: IFormStatisticArrItem[] = []
    /** 竞拍初始化数据 */
    binding_info: any = {
        binding_result: [
            {
                user_id: '1',
                name: '',
                price: '',
                avatar: '',
                height: 60,
            },
            {
                user_id: '2',
                name: '',
                price: '',
                avatar: '',
                height: 60,
            },
            {
                user_id: '3',
                name: '',
                price: '',
                avatar: '',
                height: 60,
            },
            {
                user_id: '4',
                name: '',
                price: '',
                avatar: '',
                height: 60,
            },
            {
                user_id: '5',
                name: '',
                price: '',
                avatar: '',
                height: 60,
            },
        ],
        bidding_price_avg: 0,
        bidding_student_num: 0,
    }
    /** 拍卖数据 */
    lot_arr: any[] = []
    /** 拍卖结果数据 */
    trainingStatistic: TrainingStatisticRes | Record<string, any> = {
        form_statistic_arr: [{}],
        statistic_arr: [{}],
    }

    /** 拍品信息 */
    lot_obj: any = {}

    constructor() {
        makeAutoObservable(this)
    }

    /** 获取实训结果 */
    getTrainingsStatistic = (record_id: string) => {
        getTrainingsStatisticInfo({ record_id }).then(res => {
            this.trainingStatistic = res.data
        })
    }

    /** 初始化下一件拍卖数据 */
    initBindingInfo = () => {
        this.binding_info = {
            binding_result: [
                {
                    user_id: '1',
                    name: '',
                    price: '',
                    avatar: '',
                    height: 60,
                },
                {
                    user_id: '2',
                    name: '',
                    price: '',
                    avatar: '',
                    height: 60,
                },
                {
                    user_id: '3',
                    name: '',
                    price: '',
                    avatar: '',
                    height: 60,
                },
                {
                    user_id: '4',
                    name: '',
                    price: '',
                    avatar: '',
                    height: 60,
                },
                {
                    user_id: '5',
                    name: '',
                    price: '',
                    avatar: '',
                    height: 60,
                },
            ],
            bidding_price_avg: 0,
            bidding_student_num: 0,
        }
    }

    /** 设置数据 */
    setData = (key: 'form_statistic_arr' | 'binding_info' | 'lot_arr' | 'lot_obj' | 'userInfo', value: any) => {
        this[key] = value
    }
}

const store = new Store()
export default store
